package com.frxuexi.park2209.mynews

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.blankj.utilcode.util.ToastUtils
import com.frxuexi.base.mvvm.BaseActivity
import com.frxuexi.park2209.R
import com.frxuexi.park2209.databinding.ActivityAddNewsBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class AddNewsActivity : BaseActivity<ActivityAddNewsBinding,MyNewsViewModel>() {
    override fun initData() {
        lifecycleScope.launch {
            vm.addnewsSuc.collect{
                if(it.isNotEmpty()){
                    ToastUtils.showLong(it)
                    finish()
                }
            }
        }
    }

    override fun initView() {
        binding.headerAddnews.headerTitle.text="添加文化"
        binding.btnCommitNews.setOnClickListener {
            val title = binding.addnewsTitle.text.toString()
            val value = binding.addnewsValue.text.toString()
            vm.addNews(mapOf("newsTitle" to title,"newsValue" to value,"newsTime" to getDataTime(System.currentTimeMillis())))
        }
    }

}